﻿using System;
using System.Diagnostics.CodeAnalysis;

namespace SL5.Common
{
	/// <summary>
	/// Service provider methods.
	/// </summary>
	public static class ServiceProviderMethods
	{
		#region Public Static Methods 
		/// <summary>
		/// Gets the service object of the specified type from the service provider.
		/// </summary>
		/// <typeparam name="TService">The type of the service.</typeparam>
		/// <param name="serviceProvider">The service provider.</param>
		/// <returns>TService.</returns>
		[SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")]
		public static TService GetService<TService>(this IServiceProvider serviceProvider)
			where TService : class
		{
			if (serviceProvider == null)
			{
				throw new ArgumentNullException("serviceProvider");
			}
			return (TService)serviceProvider.GetService(typeof(TService));
		}
		#endregion Public Static Methods 
	}
}